<template>
  <view class="index">
    <view class="padding">
      <Upload :maxCount="maxCount" v-model="fileList"></Upload>
    </view>
  </view>
</template>

<script>
import Upload from '@components/common/upload/index'
import { getParam } from '@utils/'
import Taro from '@tarojs/taro'

export default {
  name: 'Upload',
  data() {
    return {
      maxCount: 1,
      fileList: [],
      field: ''
    }
  },
  components: {
    Upload
  },
  created() {
    const title = getParam('title')
    if (title) {
      Taro.setNavigationBarTitle({ title })
    }
    const maxCount = getParam('max')
    if (maxCount) {
      this.maxCount = parseInt(maxCount)
    }
    this.field = getParam('field')
    const imgs = JSON.parse(getParam('imgs'))
    this.fileList = imgs.map(i => {
      return {
        path: i
      }
    })
  },
  watch: {
    fileList() {
      Taro.eventCenter.trigger('selectImg', {
        field: this.field,
        imgs: this.fileList.filter(i => i.status === 'done').map(i => i.path)
      })
    }
  },
  methods: {}
}
</script>

<style lang="scss">
.padding {
  padding: 24rpx 24rpx;
}
</style>
